<?php
namespace app\index\controller;

use app\index\model\Learn;

class Add{
    public function chooseCourse(){
        $res = input("post.");
        $learn = Learn::get($res);
        if($learn==null){
            $learn = model("Learn");
            $learn->data([
                "c_id" => $res["c_id"],
                "s_id" => $res["s_id"]
            ]);
            $learn->save();
            return true;
        } else{
            return false;
        }
    }

    public function addScore(){
        $res = input("post.");
        $learn = Learn::get([
            "c_id" => $res["c_id"],
            "s_id" => $res["s_id"]
        ]);
        if ($learn["grade"]!=null){
            return false;
        }else{
            $learn["grade"] = $res["grade"];
            $learn->save();
            return true;
        }
    }
}